package se19team1e.dao.factory;

import se19team1e.dao.abstrakt.jaas.DepartmentDAO;
import se19team1e.entity.DepartmentDTO;

/**
 * This class DAO Factory Selector will return a new instance of Property DAO
 * Factory.
 * 
 * <pre>
 * Usage:
 * 			DAOFactory daoFactory = DAOFactorySelector.getDAOFactory();
 * 			DepartmentDAO departmentDAO = daoFactory.getDepartmentDAO();
 * 			DepartmentDTO department = null;			
 * 			try {
 * 				department = (DepartmentDTO) departmentDAO
 * 						.retrieveById(jobAdvert.getDepartmentId());
 * 			}
 * </pre>
 * 
 * @see DAOFactory
 * @author Arun Manivannan
 * 
 */
public class DAOFactorySelector {
	public static DAOFactory getDAOFactory() {
		// FIXME source the factory configuration from a config file
		return getFactory("PropertyConfig");
	}

	private static DAOFactory getFactory(String factoryImpl) {
		// FIXME uncomment after configuration is done
		/*
		 * if (factoryImpl == null ) { throw new
		 * IllegalArgumentException("Factory Implementation must not be null.");
		 * }
		 */

		if (factoryImpl.equals("PropertyConfig")) {
			return new PropertyDAOFactory();
		} else if (factoryImpl.equals("MySQL")) {
			return null; // Added just for the fun of it.
		} else {
			throw new IllegalArgumentException(
					"Unsupported factory implementation.");
		}
	}
}
